package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202410;

public class leetcode20241002 {
    public int minSpeedOnTime(int[] dist,double hour){
        /**
         * 准时到达的列车最小时速
         */
        int left=-1,right=(int)1e7+1;
        while(left<right){
            int mid=left+(right-left)/2;
            if(check(mid,dist,hour)){
                right=mid;
            }else{
                left=mid+1;
            }
        }
        return left==(int)1e7+1 ? -1 : left;
    }

    boolean check(int mid,int[] dist,double hour){
        double time=0;
        for(int d : dist){
            time=Math.ceil(time);
            time+=(double) d/mid;
        }
        return hour>=time;
    }
}
